package com.imis.module.system.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.imis.base.constant.permissions.PermissionsValueConstant;
import com.imis.base.globle.Result;
import com.imis.module.base.BaseController;
import com.imis.module.system.bus.SysDictBus;
import com.imis.module.system.model.ro.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 字典管理前端控制器
 * </p>
 *
 * @author XinLau
 * @since 2020-03-19
 */
@Slf4j
@RestController
@RequestMapping("/sys/dict")
@Api(tags = {"字典管理"})
@ApiSort(2)
public class SysDictController extends BaseController<SysDictBus> {

    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询字典项接口", notes = "分页查询字典项接口")
    @RequiresPermissions(PermissionsValueConstant.DICT_PAGE)
    @ApiOperationSupport(order = 1, author = "XinLau")
    public Result pagingQuerySysDictListByParameter(PagingQueryDictDTO pagingQueryDictDTO) {
        return service.pagingQuerySysDictListByParameter(pagingQueryDictDTO);
    }

    @RequestMapping(value = "/addDict", method = RequestMethod.POST)
    @ApiOperation(value = "字典项添加接口", notes = "单条添加")
    @RequiresPermissions(PermissionsValueConstant.DICT_ADD)
    @ApiOperationSupport(order = 2, author = "XinLau")
    public Result addDict(@RequestBody @Valid SysDictAddRO sysDictAddRO) {
        return service.addDict(sysDictAddRO);
    }

    @RequestMapping(value = "/deleteDict", method = RequestMethod.GET)
    @ApiOperation(value = "字典项删除接口", notes = "单条删除")
    @RequiresPermissions(value = {PermissionsValueConstant.DICT_PAGE, PermissionsValueConstant.DICT_DELETE}, logical = Logical.AND)
    @ApiImplicitParam(name = "id", value = "字典项标识", dataType = "Long", dataTypeClass = Long.class, required = true)
    @ApiOperationSupport(order = 3, author = "XinLau")
    public Result deleteDict(@RequestParam(name = "id", required = true) Long id) {
        return service.deleteDict(id);
    }

    @RequestMapping(value = "/queryDictById", method = RequestMethod.GET)
    @ApiOperation(value = "字典值查看接口", notes = "单条查看")
    @RequiresPermissions(PermissionsValueConstant.DICT_QUERY_BY_ID)
    @ApiImplicitParam(name = "id", value = "字典项标识", dataType = "Long", dataTypeClass = Long.class, required = true)
    @ApiOperationSupport(order = 4, author = "XinLau")
    public Result queryDictById(@RequestParam(name = "id", required = true) Long id) {
        return service.queryDictById(id);
    }

    @RequestMapping(value = "/updateDict", method = RequestMethod.PUT)
    @ApiOperation(value = "字典项修改接口", notes = "单条修改")
    @RequiresPermissions(PermissionsValueConstant.DICT_UPDATE)
    @ApiOperationSupport(order = 5, author = "XinLau")
    public Result updateDict(@RequestBody @Valid SysDictUpdateRO sysDictUpdateRO) {
        return service.updateDict(sysDictUpdateRO);
    }

    @RequestMapping(value = "/getDictItemByDict", method = RequestMethod.GET)
    @ApiOperation(value = "根据字典项获取字典值", notes = "获取字典值")
    @RequiresPermissions(PermissionsValueConstant.DICT_ITEM_QUERY_BY_DICT)
    @ApiImplicitParam(name = "dictIdentification", value = "字典项标识", dataType = "Long", dataTypeClass = Long.class, required = true)
    @ApiOperationSupport(order = 6, author = "XinLau")
    public Result queryDictItemByDict(@RequestParam(name = "dictIdentification", required = true) Long dictIdentification) {
        return service.queryDictItemByDict(dictIdentification);
    }

    @RequestMapping(value = "/pagingQueryDictItem", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询字典值", notes = "分页查询字典值")
    @RequiresPermissions(PermissionsValueConstant.DICT_ITEM_PAGE)
    @ApiOperationSupport(order = 7, author = "XinLau")
    public Result pagingQuerySysDictItemListByParameter(PagingQueryDictItemDTO pagingQueryDictItemDTO) {
        return service.pagingQuerySysDictItemListByParameter(pagingQueryDictItemDTO);
    }

    @RequestMapping(value = "/addDictItem", method = RequestMethod.POST)
    @ApiOperation(value = "字典值添加接口", notes = "单条添加")
    @RequiresPermissions(PermissionsValueConstant.DICT_ITEM_ADD)
    @ApiOperationSupport(order = 8, author = "XinLau")
    public Result addDictItem(@RequestBody @Valid SysDictItemAddRO sysDictItemAddRO) {
        return service.addDictItem(sysDictItemAddRO);
    }

    @RequestMapping(value = "/deleteDictItem", method = RequestMethod.GET)
    @ApiOperation(value = "字典值删除接口", notes = "单条删除")
    @RequiresPermissions(value = {PermissionsValueConstant.DICT_ITEM_PAGE, PermissionsValueConstant.DICT_ITEM_DELETE}, logical = Logical.AND)
    @ApiImplicitParam(name = "id", value = "字典项标识", dataType = "Long", dataTypeClass = Long.class, required = true)
    @ApiOperationSupport(order = 9, author = "XinLau")
    public Result deleteDictItem(@RequestParam(name = "id", required = true) Long id) {
        return service.deleteDictItem(id);
    }

    @RequestMapping(value = "/queryDictItemById", method = RequestMethod.GET)
    @ApiOperation(value = "字典值查看接口", notes = "单条查看")
    @RequiresPermissions(PermissionsValueConstant.DICT_ITEM_QUERY_BY_ID)
    @ApiImplicitParam(name = "id", value = "字典项标识", dataType = "Long", dataTypeClass = Long.class, required = true)
    @ApiOperationSupport(order = 10, author = "XinLau")
    public Result queryDictItemById(@RequestParam(name = "id", required = true) Long id) {
        return service.queryDictItemById(id);
    }

    @RequestMapping(value = "/updateDictItem", method = RequestMethod.PUT)
    @ApiOperation(value = "字典值修改接口", notes = "单条修改")
    @RequiresPermissions(PermissionsValueConstant.DICT_ITEM_UPDATE)
    @ApiOperationSupport(order = 11, author = "XinLau")
    public Result updateDictItem(@RequestBody @Valid SysDictItemUpdateRO sysDictItemUpdateRO) {
        return service.updateDictItem(sysDictItemUpdateRO);
    }

}